define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'merchant/index' + location.search,
                    // add_url: 'merchant/add',
                    edit_url: 'merchant/edit',
                    // del_url: 'merchant/del',
                    multi_url: 'merchant/multi',
                    import_url: 'merchant/import',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        {
                            field: 'no',
                            title: __('序号'),
                            formatter: function(value, row, index) {
                                //获取每页显示的数量
                                var pageSize = table.bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            },
                            operate: false
                        },
                        // { field: 'avatar', title: __('头像'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        { field: 'nickname', title: __('Nick'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'mobile', title: __('Phone') },
                        { field: 'mercode', title: __('Number'), operate: 'LIKE' },
                        { field: 'addr', title: __('投放地址') },
                        { field: 'real_name', title: __('姓名') },
                        { field: 'real_idcard', title: __('idCard') },
                        { field: 'card_front', title: __('身份证正面'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        { field: 'card_back', title: __('身份证反面'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        { field: 'license', title: __('营业执照'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false },
                        { field: 'nums', title: __('关联客户') },
                        { field: 'todayNums', title: __('今日注册') },
                        { field: 'volume', title: __('今日访问') },
                        { field: 'status', title: __('账号状态'), searchList: { "1": __('Is_status 1'), "2": __('Is_status 2') }, formatter: Table.api.formatter.status },
                        { field: 'snick', title: __('投放状态'), searchList: { "1": __('Is_status 1'), "2": __('Is_status 2') }, formatter: Table.api.formatter.status },
                        { field: 'active_time', title: __('激活时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'jointime', title: __('加入时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});